package springinpractice.ch4.r4_3.dao;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import springinpractice.ch4.r4_3.model.User;

/*
 * Author       :       Willie Wheeler and John Wheeler
 * Book         :       'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 */

@Repository("userDao")
public class HbnUserDao extends HbnAbstractDao<User> implements UserDao {

	@SuppressWarnings("unchecked")
	public User findByUsername(String username) {
		Query q = getSession().createQuery("from User where username = ?");
		q.setParameter(0, username);
		return (User) q.uniqueResult();
	}
	
	@SuppressWarnings("unchecked")
	public User findByEmail(String email) {
		Query q = getSession().createQuery("from User where email = ?");
		q.setParameter(0, email);
		return (User) q.uniqueResult();
	}
}
